package com.ruoyi.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.system.domain.vo.ArchiveRecoverTaskVo;
import com.ruoyi.system.domain.bo.ArchiveRecoverTaskBo;
import com.ruoyi.system.service.IArchiveRecoverTaskService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 归档恢复任务控制器
 * 前端访问路由地址为:/system/recoverTask
 *
 * @author ruoyi
 * @date 2024-12-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/recoverTask")
public class ArchiveRecoverTaskController extends BaseController {

    private final IArchiveRecoverTaskService iArchiveRecoverTaskService;

    /**
     * 查询归档恢复任务列表
     */
    @SaCheckPermission("system:recoverTask:list")
    @GetMapping("/list")
    public TableDataInfo<ArchiveRecoverTaskVo> list(ArchiveRecoverTaskBo bo, PageQuery pageQuery) {
        return iArchiveRecoverTaskService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出归档恢复任务列表
     */
    @SaCheckPermission("system:recoverTask:export")
    @Log(title = "归档恢复任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArchiveRecoverTaskBo bo, HttpServletResponse response) {
        List<ArchiveRecoverTaskVo> list = iArchiveRecoverTaskService.queryList(bo);
        ExcelUtil.exportExcel(list, "归档恢复任务", ArchiveRecoverTaskVo.class, response);
    }

    /**
     * 获取归档恢复任务详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:recoverTask:query")
    @GetMapping("/{id}")
    public R<ArchiveRecoverTaskVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iArchiveRecoverTaskService.queryVoById(id));
    }

    /**
     * 新增归档恢复任务
     */
    @SaCheckPermission("system:recoverTask:add")
    @Log(title = "归档恢复任务", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArchiveRecoverTaskBo bo) {
        return toAjax(iArchiveRecoverTaskService.insertByBo(bo));
    }

    /**
     * 修改归档恢复任务
     */
    @SaCheckPermission("system:recoverTask:edit")
    @Log(title = "归档恢复任务", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArchiveRecoverTaskBo bo) {
        return toAjax(iArchiveRecoverTaskService.updateByBo(bo));
    }

    /**
     * 删除归档恢复任务
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:recoverTask:remove")
    @Log(title = "归档恢复任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iArchiveRecoverTaskService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 新增归档恢复任务
     */
    @SaCheckPermission("system:recoverTask:execute")
    @Log(title = "执行归档恢复任务", businessType = BusinessType.INSERT)
    @GetMapping("/execute/{id}")
    public R<Void> execute(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return toAjax(iArchiveRecoverTaskService.execute(id));
    }
}
